/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package GUI.EditorMenu;

import B3D_Elements.B3D_Filters.B3D_BasicSSAO;
import B3D_Elements.B3D_Filters.B3D_Bloom;
import B3D_Elements.B3D_Filters.B3D_Cartoon;
import B3D_Elements.B3D_Filters.B3D_ColorScale;
import B3D_Elements.B3D_Filters.B3D_Crosshatch;
import B3D_Elements.B3D_Filters.B3D_DepthOfField;
import B3D_Elements.B3D_Filters.B3D_Fog;
import B3D_Elements.B3D_Filters.B3D_FrostedGlass;
import B3D_Elements.B3D_Filters.B3D_LightScattering;
import B3D_Elements.B3D_Filters.B3D_OldFilm;
import B3D_Elements.B3D_Filters.B3D_Posterization;
import B3D_Elements.B3D_Filters.B3D_SSAO;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_DLShadow;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_PLShadow;
import B3D_Elements.B3D_Filters.B3D_Shadows.B3D_SLShadow;
import B3D_Elements.B3D_Filters.B3D_Water;
import B3D_Elements.Others.B3D_MotionEvent;
import B3D_Elements.Others.B3D_MotionPath;
import GUI.Components.AssetButton;
import GUI.Dialogs.AssetChooserDialog;
import GUI.Dialogs.CreateParticleEmitterDialog;
import GUI.Dialogs.CreateSkyBoxDialog;
import GUI.Dialogs.SelectDialog;
import General.CurrentData;
import com.jme3.animation.LoopMode;
import com.jme3.cinematic.MotionPath;
import com.jme3.cinematic.events.MotionEvent;
import com.jme3.light.AmbientLight;
import com.jme3.light.DirectionalLight;
import com.jme3.light.Light;
import com.jme3.light.PointLight;
import com.jme3.light.SpotLight;
import com.jme3.material.Material;
import com.jme3.math.ColorRGBA;
import com.jme3.math.FastMath;
import com.jme3.math.Spline;
import com.jme3.math.Vector3f;
import com.jme3.post.filters.BloomFilter;
import com.jme3.post.filters.CartoonEdgeFilter;
import com.jme3.post.filters.CrossHatchFilter;
import com.jme3.post.filters.DepthOfFieldFilter;
import com.jme3.post.filters.FogFilter;
import com.jme3.post.filters.LightScatteringFilter;
import com.jme3.post.filters.PosterizationFilter;
import com.jme3.post.ssao.SSAOFilter;
import com.jme3.scene.Geometry;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import com.jme3.scene.shape.Cylinder;
import com.jme3.scene.shape.Sphere;
import com.jme3.scene.shape.Torus;
import com.jme3.water.WaterFilter;
import com.shaderblow.filter.basicssao.BasicSSAO;
import com.shaderblow.filter.frostedglass.FrostedGlassFilter;
import com.shaderblow.filter.oldfilm.OldFilmFilter;
import com.simsilica.lemur.geom.MBox;
import other.Wizard;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;
import java.util.concurrent.Callable;
import javax.swing.*;
import other.ColorScaleFilterWithGetters;
import other.DirectionalLightShadowFilterWithMapSizeGetter;
import other.ObjectToElementConverter;
import other.PointLightShadowFilterWithMapSizeGetter;
import other.SpotLightShadowFilterWithMapSizeGetter;

/**
 *
 * @author David
 */
public class AddMenu extends JMenu
{

    private Object3DMenu object3DMenu = new Object3DMenu();
    private LightMenu lightMenu = new LightMenu();
    private FilterMenu filterMenu = new FilterMenu();
    private JMenuItem motionPathItem = new JMenuItem("Motion Path");

    public AddMenu()
    {
        setEnabled(false);
        setText("Add");
        add(object3DMenu);
        add(lightMenu);
        add(filterMenu);
        add(motionPathItem);
        motionPathItem.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                B3D_Elements.B3D_Element element;
                Vector<String> objects = new Vector<String>();
                objects.add("Camera");
                Vector<Geometry> allGeometrys = new Vector<Geometry>();
                Wizard.insertAllGeometrys(CurrentData.getEditorWindow().getB3DApplication().getSceneNode(), allGeometrys);
                Collections.sort(allGeometrys, new Comparator<Geometry>()
                {
                    public int compare(Geometry o1, Geometry o2)
                    {
                        return o1.getName().compareTo(o2.getName());
                    }
                });
                for (Geometry geometry : allGeometrys)
                {
                    objects.add(geometry.getName());
                }
                SelectDialog selectDialog = new SelectDialog("Moving Object", objects.toArray());
                if (selectDialog.isOk())
                {
                    MotionEvent motionEvent = null;
                    if (selectDialog.getSelectedIndex() == 0)
                    {
                        motionEvent = new MotionEvent(CurrentData.getEditorWindow().getB3DApplication().getCamNode(), new MotionPath());
                        motionEvent.setLoopMode(LoopMode.DontLoop);
                        element = new B3D_MotionEvent(
                                "Camera Motion Path",
                                null,
                                new B3D_MotionPath(
                                null,
                                motionEvent.getPath().getCurveTension(),
                                motionEvent.getSpeed(),
                                ColorRGBA.Gray,
                                motionEvent.getPath().isCycle(),
                                motionEvent.getRotation(),
                                motionEvent.getDirectionType(),
                                motionEvent.getLoopMode()));
                        motionEvent.getPath().addWayPoint(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation());
                        motionEvent.getPath().addWayPoint(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(0, 10, 0));
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(motionEvent, element);
                    } else
                    {
                        motionEvent = new MotionEvent(allGeometrys.get(selectDialog.getSelectedIndex() - 1), new MotionPath());
                        motionEvent.setLoopMode(LoopMode.DontLoop);
                        element = new B3D_MotionEvent(
                                CurrentData.getEditorWindow().getB3DApplication().getElementList().getElement(
                                allGeometrys.get(selectDialog.getSelectedIndex() - 1)).getName() + " Motion Path",
                                CurrentData.getEditorWindow().getB3DApplication().getElementList().getElement(
                                allGeometrys.get(selectDialog.getSelectedIndex() - 1)).getID(),
                                new B3D_MotionPath(
                                null,
                                motionEvent.getPath().getCurveTension(),
                                motionEvent.getSpeed(),
                                ColorRGBA.Green,
                                motionEvent.getPath().isCycle(),
                                motionEvent.getRotation(),
                                motionEvent.getDirectionType(),
                                motionEvent.getLoopMode()));
                        allGeometrys.get(selectDialog.getSelectedIndex() - 1).setUserData("motionEventName", element.getName());
                        allGeometrys.get(selectDialog.getSelectedIndex() - 1).setUserData("motionEventLookAtName", element.getName());
                        motionEvent.getPath().addWayPoint(motionEvent.getSpatial().getWorldTranslation());
                        motionEvent.getPath().addWayPoint(motionEvent.getSpatial().getWorldTranslation().add(0, 10, 0));
                        CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(motionEvent, element);
                    }
                    motionEvent.getPath().setPathSplineType(Spline.SplineType.CatmullRom);
                    CurrentData.getEditorWindow().getB3DApplication().getMotionEvents().add(motionEvent);
                    CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                    CurrentData.getEditorWindow().getB3DApplication().updateSelectedMotionPath();
                }
            }
        });
    }

    public class FilterMenu extends JMenu
    {

        private JMenuItem basicSSAOItem = new JMenuItem("Basic SSAO");
        private JMenuItem bloomItem = new JMenuItem("Bloom");
        private JMenuItem cartoonItem = new JMenuItem("Cartoon");
        private JMenuItem colorScaleItem = new JMenuItem("Color Scale");
        private JMenuItem crossHatchItem = new JMenuItem("Crosshatch");
        private JMenuItem dofItem = new JMenuItem("Depth of Field");
        private JMenuItem fogItem = new JMenuItem("Fog");
        private JMenuItem frostedGlassItem = new JMenuItem("Frosted Glass");
        private JMenuItem lightScatteringItem = new JMenuItem("Light Scattering");
        private JMenuItem oldFilmItem = new JMenuItem("Old Film");
        private JMenuItem posterizationItem = new JMenuItem("Posterization");
        private JMenu shadowMenu = new JMenu("Shadow");
        private JMenuItem dlShadowItem = new JMenuItem("Directionallight Shadow");
        private JMenuItem plShadowItem = new JMenuItem("Pointlight Shadow");
        private JMenuItem slShadowItem = new JMenuItem("Spotlight Shadow");
        private JMenuItem ssaoItem = new JMenuItem("SSAO");
        private JMenuItem waterItem = new JMenuItem("Water");

        public FilterMenu()
        {
            setText("Filter");
            setIcon(new ImageIcon("dat//img//menu//filter.png"));
            add(basicSSAOItem);
            add(bloomItem);
            add(cartoonItem);
            add(colorScaleItem);
            add(crossHatchItem);
            add(dofItem);
            add(fogItem);
            add(frostedGlassItem);
            add(lightScatteringItem);
            add(oldFilmItem);
            add(posterizationItem);
            add(shadowMenu);
            shadowMenu.add(dlShadowItem);
            shadowMenu.add(plShadowItem);
            shadowMenu.add(slShadowItem);
            add(ssaoItem);
            add(waterItem);
            initActions();
        }

        private void initActions()
        {
            basicSSAOItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            BasicSSAO basicSSAO = new BasicSSAO();
                            B3D_BasicSSAO b3D_BasicSSAO = ObjectToElementConverter.convertBasicSSAO(basicSSAO);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(basicSSAO);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(basicSSAO, b3D_BasicSSAO);
                            return null;
                        }
                    });
                }
            });
            oldFilmItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            OldFilmFilter oldFilmFilter = new OldFilmFilter();
                            B3D_OldFilm b3D_OldFilm = ObjectToElementConverter.convertOldFilm(oldFilmFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(oldFilmFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(oldFilmFilter, b3D_OldFilm);
                            return null;
                        }
                    });
                }
            });
            colorScaleItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            ColorScaleFilterWithGetters csfwg = new ColorScaleFilterWithGetters();
                            B3D_ColorScale b3D_ColorScale = ObjectToElementConverter.convertColorScale(csfwg);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(csfwg);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(csfwg, b3D_ColorScale);
                            return null;
                        }
                    });
                }
            });
            frostedGlassItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            FrostedGlassFilter frostedGlassFilter = new FrostedGlassFilter();
                            B3D_FrostedGlass b3D_FrostedGlass = ObjectToElementConverter.convertFrostedGlass(frostedGlassFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(frostedGlassFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(frostedGlassFilter, b3D_FrostedGlass);
                            return null;
                        }
                    });
                }
            });
            dlShadowItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    SelectDialog selectResolutionDialog = new SelectDialog("Shadow Resolution", new String[]
                    {
                        "64", "128", "256", "512", "1024", "2048"
                    });
                    final DirectionalLightShadowFilterWithMapSizeGetter shadowFilter = new DirectionalLightShadowFilterWithMapSizeGetter(
                            CurrentData.getEditorWindow().getB3DApplication().getAssetManager(),
                            Integer.parseInt(selectResolutionDialog.getSelectedValue()),
                            3);
                    Vector<String> names = new Vector<String>();
                    Vector<DirectionalLight> lights = new Vector<DirectionalLight>();
                    for (Light l : CurrentData.getEditorWindow().getB3DApplication().getSceneNode().getWorldLightList())
                    {
                        if (l instanceof DirectionalLight)
                        {
                            names.add(l.getName());
                            lights.add((DirectionalLight) l);
                        }
                    }
                    Collections.sort(names, new Comparator<String>()
                    {
                        public int compare(String o1, String o2)
                        {
                            return o1.compareTo(o2);
                        }
                    });
                    Collections.sort(lights, new Comparator<DirectionalLight>()
                    {
                        public int compare(DirectionalLight o1, DirectionalLight o2)
                        {
                            return o1.getName().compareTo(o2.getName());
                        }
                    });
                    SelectDialog selectDialog = new SelectDialog("Select Light Source", names.toArray());
                    final DirectionalLight selectedLight = lights.get(selectDialog.getSelectedIndex());
                    shadowFilter.setLight(selectedLight);
                    shadowFilter.setName(selectedLight.getName() + " Shadow");
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            B3D_DLShadow b3D_Bloom = ObjectToElementConverter.convertDirectionalLightShadow(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(shadowFilter, b3D_Bloom);
                            return null;
                        }
                    });
                }
            });
            plShadowItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    SelectDialog selectResolutionDialog = new SelectDialog("Shadow Resolution", new String[]
                    {
                        "64", "128", "256", "512", "1024", "2048"
                    });
                    final PointLightShadowFilterWithMapSizeGetter shadowFilter = new PointLightShadowFilterWithMapSizeGetter(
                            CurrentData.getEditorWindow().getB3DApplication().getAssetManager(),
                            Integer.parseInt(selectResolutionDialog.getSelectedValue()));
                    Vector<String> names = new Vector<String>();
                    Vector<PointLight> lights = new Vector<PointLight>();
                    for (Light l : CurrentData.getEditorWindow().getB3DApplication().getSceneNode().getWorldLightList())
                    {
                        if (l instanceof PointLight)
                        {
                            names.add(l.getName());
                            lights.add((PointLight) l);
                        }
                    }
                    Collections.sort(names, new Comparator<String>()
                    {
                        public int compare(String o1, String o2)
                        {
                            return o1.compareTo(o2);
                        }
                    });
                    Collections.sort(lights, new Comparator<PointLight>()
                    {
                        public int compare(PointLight o1, PointLight o2)
                        {
                            return o1.getName().compareTo(o2.getName());
                        }
                    });
                    SelectDialog selectDialog = new SelectDialog("Select Light Source", names.toArray());
                    final PointLight selectedLight = lights.get(selectDialog.getSelectedIndex());
                    shadowFilter.setLight(selectedLight);
                    shadowFilter.setName(selectedLight.getName() + " Shadow");
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            B3D_PLShadow b3D_PLShadow = ObjectToElementConverter.convertPointLightShadow(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(shadowFilter, b3D_PLShadow);
                            return null;
                        }
                    });
                }
            });
            slShadowItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    SelectDialog selectResolutionDialog = new SelectDialog("Shadow Resolution", new String[]
                    {
                        "64", "128", "256", "512", "1024", "2048"
                    });
                    final SpotLightShadowFilterWithMapSizeGetter shadowFilter = new SpotLightShadowFilterWithMapSizeGetter(
                            CurrentData.getEditorWindow().getB3DApplication().getAssetManager(),
                            Integer.parseInt(selectResolutionDialog.getSelectedValue()));
                    Vector<String> names = new Vector<String>();
                    Vector<SpotLight> lights = new Vector<SpotLight>();
                    for (Light l : CurrentData.getEditorWindow().getB3DApplication().getSceneNode().getWorldLightList())
                    {
                        if (l instanceof SpotLight)
                        {
                            names.add(l.getName());
                            lights.add((SpotLight) l);
                        }
                    }
                    Collections.sort(names, new Comparator<String>()
                    {
                        public int compare(String o1, String o2)
                        {
                            return o1.compareTo(o2);
                        }
                    });
                    Collections.sort(lights, new Comparator<SpotLight>()
                    {
                        public int compare(SpotLight o1, SpotLight o2)
                        {
                            return o1.getName().compareTo(o2.getName());
                        }
                    });
                    SelectDialog selectDialog = new SelectDialog("Select Light Source", names.toArray());
                    final SpotLight selectedLight = lights.get(selectDialog.getSelectedIndex());
                    shadowFilter.setLight(selectedLight);
                    shadowFilter.setName(selectedLight.getName() + " Shadow");
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            B3D_SLShadow b3D_SLShadow = ObjectToElementConverter.convertSpotLightShadow(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(shadowFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(shadowFilter, b3D_SLShadow);
                            return null;
                        }
                    });
                }
            });
            bloomItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            BloomFilter bloomFilter = new BloomFilter();
                            B3D_Bloom b3D_Bloom = ObjectToElementConverter.convertBloom(bloomFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(bloomFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(bloomFilter, b3D_Bloom);
                            return null;
                        }
                    });
                }
            });
            cartoonItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            CartoonEdgeFilter cartoonFilter = new CartoonEdgeFilter();
                            B3D_Cartoon b3D_Cartoon = ObjectToElementConverter.convertCartoon(cartoonFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(cartoonFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(cartoonFilter, b3D_Cartoon);
                            return null;
                        }
                    });
                }
            });
            crossHatchItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            CrossHatchFilter crossHatchFilter = new CrossHatchFilter();
                            Float[] llevels = new Float[5];
                            llevels[0] = crossHatchFilter.getLuminance1();
                            llevels[1] = crossHatchFilter.getLuminance2();
                            llevels[2] = crossHatchFilter.getLuminance3();
                            llevels[3] = crossHatchFilter.getLuminance4();
                            llevels[4] = crossHatchFilter.getLuminance5();
                            B3D_Crosshatch b3D_Crosshatch = ObjectToElementConverter.convertCrosshatch(crossHatchFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(crossHatchFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(crossHatchFilter, b3D_Crosshatch);
                            return null;
                        }
                    });
                }
            });
            dofItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            DepthOfFieldFilter depthOfFieldFilter = new DepthOfFieldFilter();
                            B3D_DepthOfField b3D_DepthOfField = ObjectToElementConverter.convertDOF(depthOfFieldFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(depthOfFieldFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(depthOfFieldFilter, b3D_DepthOfField);
                            return null;
                        }
                    });
                }
            });
            fogItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            FogFilter fogFilter = new FogFilter();
                            B3D_Fog b3D_Fog = ObjectToElementConverter.convertFog(fogFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(fogFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(fogFilter, b3D_Fog);
                            return null;
                        }
                    });
                }
            });
            lightScatteringItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            LightScatteringFilter scatteringFilter = new LightScatteringFilter(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation());
                            B3D_LightScattering b3D_LightScattering = ObjectToElementConverter.convertLightScattering(scatteringFilter);
                            //CurrentData.getEditorWindow().getB3DApplication().getLightScatteringModels().add(new LightScatteringModel(scatteringFilter));
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(scatteringFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(scatteringFilter, b3D_LightScattering);
                            return null;
                        }
                    });
                }
            });
            posterizationItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            PosterizationFilter posterizationFilter = new PosterizationFilter();
                            B3D_Posterization b3D_Posterization = ObjectToElementConverter.convertPosterization(posterizationFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(posterizationFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(posterizationFilter, b3D_Posterization);
                            return null;
                        }
                    });
                }
            });
            ssaoItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            SSAOFilter ssaoFilter = new SSAOFilter();
                            B3D_SSAO b3d_ssao = ObjectToElementConverter.convertSSAO(ssaoFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(ssaoFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(ssaoFilter, b3d_ssao);
                            return null;
                        }
                    });
                }
            });
            waterItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            WaterFilter waterFilter = new WaterFilter(CurrentData.getEditorWindow().getB3DApplication().getSceneNode(), Vector3f.ZERO);
                            B3D_Water water = ObjectToElementConverter.convertWater(waterFilter);
                            CurrentData.getEditorWindow().getB3DApplication().getFilterPostProcessor().addFilter(waterFilter);
                            CurrentData.getEditorWindow().getB3DApplication().setSyncTree(true);
                            CurrentData.getEditorWindow().getB3DApplication().getElementList().putByObject(waterFilter, water);
                            return null;
                        }
                    });
                }
            });
        }
    }

    public class LightMenu extends JMenu
    {

        private JMenuItem ambientItem = new JMenuItem("Ambient Light");
        private JMenuItem directionalItem = new JMenuItem("Directional Light");
        private JMenuItem pointItem = new JMenuItem("Point Light");
        private JMenuItem spotItem = new JMenuItem("Spot Light");

        public LightMenu()
        {
            setText("Light");
            setIcon(new ImageIcon("dat//img//menu//light.png"));
            add(ambientItem);
            add(directionalItem);
            add(pointItem);
            add(spotItem);
            initActions();
        }

        private void initActions()
        {
            ambientItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            AmbientLight tempLight = new AmbientLight();
                            tempLight.setName("Ambient");
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().addLight(tempLight);
                            return null;
                        }
                    });
                }
            });
            directionalItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            DirectionalLight tempLight = new DirectionalLight();
                            tempLight.setDirection(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection());
                            tempLight.setName("Directional");
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().addLight(tempLight);
                            return null;
                        }
                    });
                }
            });
            pointItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            PointLight tempLight = new PointLight();
                            tempLight.setPosition(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            tempLight.setRadius(10);
                            tempLight.setName("Point");
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().addLight(tempLight);
                            return null;
                        }
                    });
                }
            });
            spotItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            SpotLight tempLight = new SpotLight();
                            tempLight.setPosition(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            tempLight.setSpotInnerAngle(15f * FastMath.DEG_TO_RAD);
                            tempLight.setSpotOuterAngle(35f * FastMath.DEG_TO_RAD);
                            tempLight.setSpotRange(100);
                            tempLight.setDirection(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection());
                            tempLight.setName("Spot");
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().addLight(tempLight);
                            return null;
                        }
                    });
                }
            });
        }
    }

    public class Object3DMenu extends JMenu
    {

        private JMenuItem nodeItem = new JMenuItem("Node");
        private JMenu meshMenu = new JMenu("Mesh");
        private JMenuItem boxItem = new JMenuItem("Box");
        private JMenuItem cylinderItem = new JMenuItem("Cylinder");
        private JMenuItem sphereItem = new JMenuItem("Sphere");
        private JMenuItem torusItem = new JMenuItem("Torus");
        private JMenuItem modelItem = new JMenuItem("Model");
        private JMenuItem particleEmitterItem = new JMenuItem("Particle Effect");
        private JMenuItem skyBoxMenuItem = new JMenuItem("Skybox");

        public Object3DMenu()
        {
            setText("3D Object");
            setIcon(new ImageIcon("dat//img//menu//3dobj.png"));
            add(nodeItem);
            add(meshMenu);
            meshMenu.add(boxItem);
            meshMenu.add(cylinderItem);
            meshMenu.add(sphereItem);
            meshMenu.add(torusItem);
            add(modelItem);
            add(particleEmitterItem);
            add(skyBoxMenuItem);
            initActions();
        }

        private void initActions()
        {
            nodeItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                    {
                        public Void call() throws Exception
                        {
                            Node node = new Node("Node");
                            node.setUserData("angles", new Vector3f());
                            node.setUserData("scale", new Vector3f(1, 1, 1));
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                node.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(node);
                            return null;
                        }
                    });
                }
            });
            modelItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    final String name = new AssetChooserDialog(AssetButton.AssetType.Model, true).getSelectedAssetName();
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Void>()
                    {
                        public Void call() throws Exception
                        {
                            /*Model itself*/
                            Spatial s = CurrentData.getEditorWindow().getB3DApplication().getAssetManager().loadModel(name);
                            s.setUserData("angles", new Vector3f());
                            s.setUserData("scale", new Vector3f(1, 1, 1));
                            s.setUserData("modelName", name);
                            s.setName("Model");
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                s.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            /*Set UserData to all children*/
                            if (s instanceof Node)
                            {
                                Vector<Geometry> geoms = new Vector<Geometry>();
                                Wizard.insertAllGeometrys((Node) s, geoms);
                                for (Geometry g : geoms)
                                {
                                    g.setUserData("angles", new Vector3f());
                                    g.setUserData("scale", new Vector3f(1, 1, 1));
                                }
                            }
                            CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(s);
                            return null;
                        }
                    });
                }
            });
            particleEmitterItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    new CreateParticleEmitterDialog();
                }
            });
            skyBoxMenuItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    new CreateSkyBoxDialog();
                }
            });
            boxItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            /*Lemur*/
                            Geometry g = new Geometry("Box", new MBox(1, 1, 1f, 1, 1, 1));
                            g.setUserData("xSlices", 1);
                            g.setUserData("ySlices", 1);
                            g.setUserData("zSlices", 1);
                            g.setUserData("angles", new Vector3f());
                            g.setUserData("scale", new Vector3f(1, 1, 1));
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                g.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            g.setMaterial(new Material(CurrentData.getEditorWindow().getB3DApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"));

                            /*JME-Box*/
                            /*
                             Geometry g = new Geometry("Box", new Box(1, 1, 1));
                             g.setUserData("angles", new Vector3f());
                             g.setUserData("scale", new Vector3f(1, 1, 1));
                             g.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                             g.setMaterial(new Material(CurrentData.getEditorWindow().getB3DApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"));
                             */
                            return CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(g);
                        }
                    });
                }
            });
            sphereItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            Geometry g = new Geometry("Sphere", new Sphere(10, 10, 1));
                            g.setUserData("angles", new Vector3f());
                            g.setUserData("scale", new Vector3f(1, 1, 1));
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                g.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            g.setMaterial(new Material(CurrentData.getEditorWindow().getB3DApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"));
                            return CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(g);
                        }
                    });
                }
            });
            cylinderItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            Geometry g = new Geometry("Cylinder", new Cylinder(10, 10, 1, 1, 1, true, false));
                            g.setUserData("angles", new Vector3f());
                            g.setUserData("scale", new Vector3f(1, 1, 1));
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                g.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            g.setMaterial(new Material(CurrentData.getEditorWindow().getB3DApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"));
                            return CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(g);
                        }
                    });
                }
            });
            torusItem.addActionListener(new ActionListener()
            {
                public void actionPerformed(ActionEvent e)
                {
                    CurrentData.getEditorWindow().getB3DApplication().enqueue(new Callable<Integer>()
                    {
                        public Integer call() throws Exception
                        {
                            Geometry g = new Geometry("Torus", new Torus(10, 10, 1, 2));
                            g.setUserData("angles", new Vector3f());
                            g.setUserData("scale", new Vector3f(1, 1, 1));
                            if (CurrentData.getEditorWindow().getB3DApplication().getSelectedNode().equals(CurrentData.getEditorWindow().getB3DApplication().getSceneNode()))
                            {
                                g.setLocalTranslation(CurrentData.getEditorWindow().getB3DApplication().getCamera().getLocation().add(CurrentData.getEditorWindow().getB3DApplication().getCamera().getDirection().mult(10)));
                            }
                            g.setMaterial(new Material(CurrentData.getEditorWindow().getB3DApplication().getAssetManager(), "Common/MatDefs/Misc/Unshaded.j3md"));
                            return CurrentData.getEditorWindow().getB3DApplication().getSceneNode().attachChild(g);
                        }
                    });
                }
            });
        }
    }

    public Object3DMenu getObject3DMenu()
    {
        return object3DMenu;
    }
}
